package com.gaojiabao.panghu.controller;

import com.gaojiabao.panghu.data.dto.ConditionDto;
import com.gaojiabao.panghu.data.pojo.Community;
import com.gaojiabao.panghu.service.CommunityService;
import com.gaojiabao.panghu.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: gaojiabao
 * @Date: 2024/11/3 15:56
 */
@RestController
@RequestMapping("/community")
public class CommunityController {
    @Resource
    private CommunityService communityService;

    /**
     * 分页查询小区数据
     * /community/pageList/{currentPage}/{pageSize}
     *
     * @param currentPage 当前页码
     * @param pageSize    分页大小
     */
    @PostMapping("/pageList/{currentPage}/{pageSize}")
    public Result<?> getCommunityPageList(@PathVariable Integer currentPage,
                                          @PathVariable Integer pageSize,
                                          @RequestBody(required = false) ConditionDto conditionDto) {
        return communityService.getCommunityList(currentPage, pageSize, conditionDto);
    }

    /**
     * 根据id查询小区的数据
     * /community//getCommunityById/{id}
     *
     * @param id 小区id
     */
    @GetMapping("/getCommunityById/{id}")
    public Result<?> getCommunityById(@PathVariable String id) {
        return communityService.getCommunityById(id);
    }

    /**
     * 逻辑删除小区
     * restful风格 /community/{id}
     *
     * @param id 小区id
     */
    @DeleteMapping("/{id}")
    public Result<?> deleteCommunityById(@PathVariable String id) {
        return communityService.deleteCommunityById(id);
    }


    /**
     * 编辑小区 restful分割
     *
     * @param community 修改后的community
     */
    @PutMapping()
    public Result<?> updateCommunity(@RequestBody Community community) {
        return communityService.updateCommunity(community);
    }

    /**
     * 新增小区
     * /addCommunity
     *
     * @param community 新增社区数据
     */
    @PostMapping("/addCommunity")
    public Result<?> addCommunity(@RequestBody Community community) {
        return communityService.addCommunity(community);
    }

    /**
     * 社区下拉框数据
     * /community/selectOption
     */
    @GetMapping("/selectOption")
    public Result<?> selectOption(){
        return communityService.selectOption();
    }
}
